home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / utilities / wb / zoom_v14.lha / Zoom_v1.4 / zoom!.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-31  |  13.4 KB  |  485 lines

  1. ;/*
  2. sc ignore=73 debug=line Zoom!.c
  3. slink from lib:c.o Zoom!.o to Zoom! LIB LIB:sc.lib LIB:amiga.lib SC SD ND NOICONS
  4. delete Zoom!.o
  5. quit
  6.  
  7. */
  8.  
  9. #include <exec/memory.h>
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #include <intuition/intuitionbase.h>
  13. #include <graphics/gfx.h>
  14. #include <dos/dos.h>
  15. #include <devices/timer.h>
  16. #include <3AM/libraries/bitmap.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19.  
  20. #include <clib/alib_protos.h>
  21. #include <clib/exec_protos.h>
  22. #include <clib/dos_protos.h>
  23. #include <clib/graphics_protos.h>
  24. #include <clib/intuition_protos.h>
  25. #include <3AM/clib/bitmap_protos.h>
  26. #include <3AM/pragmas/bitmap_pragmas.h>
  27.  
  28. UWORD chip Lens_data[] = {
  29. 0x0000, 0x0000, 0x0000, 0x0700, 0x0700, 0x1FC0, 0x18C0, 0x37E0, 0x3060, 0x68B0, 0x2020, 0x5070,
  30. 0x4010, 0xA038, 0x4010, 0xA038, 0x4010, 0xA038, 0x2020, 0x5050, 0x3060, 0x48B0,
  31. 0x18F0, 0x2718, 0x0738, 0x18CC, 0x001C, 0x0726, 0x000E, 0x0013, 0x0004, 0x000E,
  32. 0x0000, 0x0004, 0x0000, 0x0000 };
  33.  
  34. UWORD chip SPlus_data[] = {
  35. 0x7FFF,0xC000,0x7FFF,0xC000,0x7F3F,0xC000,0x7F3F,0xC000,0x7807,0xC000,0x7F3F,0xC000,
  36. 0x7F3F,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0xFFFF,0x8000,0xFE1F,0x8000,
  37. 0xFEDF,0x8000,0xF0C3,0x8000,0xF7FB,0x8000,0xF0C3,0x8000,0xFEDF,0x8000,0xFE1F,0x8000,
  38. 0xFFFF,0x8000,0x8000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  39. 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 };
  40.  
  41. UWORD chip SMinus_data[] = {
  42. 0x7FFF,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0x7807,0xC000,0x7FFF,0xC000,
  43. 0x7FFF,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0xFFFF,0x8000,0xFFFF,0x8000,
  44. 0xFFFF,0x8000,0xF003,0x8000,0xF7FB,0x8000,0xF003,0x8000,0xFFFF,0x8000,0xFFFF,0x8000,
  45. 0xFFFF,0x8000,0x8000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  46. 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 };
  47.  
  48. UWORD chip SAutoPlus_data[] = {
  49. 0x7FFF,0xC000,0x7FFF,0xC000,0x767F,0xC000,0x66FF,0xC000,0x67E7,0xC000,0x7081,0xC000,
  50. 0x7FE7,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0xFFFF,0x8000,0xF07F,0x8000,
  51. 0xEFBF,0x8000,0xDFC3,0x8000,0xDF18,0x8000,0xEF7E,0x8000,0xF018,0x8000,0xFFC3,0x8000,
  52. 0xFFFF,0x8000,0x8000,0x0000 };
  53.  
  54. UWORD chip SAutoMinus_data[] = {
  55. 0x7FFF,0xC000,0x7FFF,0xC000,0x767F,0xC000,0x66FF,0xC000,0x67BF,0xC000,0x70FF,0xC000,
  56. 0x7F81,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0x7FFF,0xC000,0xFFFF,0x8000,0xF07F,0x8000,
  57. 0xEFBF,0x8000,0xDFDF,0x8000,0xDFDF,0x8000,0xEF00,0x8000,0xF07E,0x8000,0xFF00,0x8000,
  58. 0xFFFF,0x8000,0x8000,0x0000 };
  59.  
  60. struct Image SPlus_image = { 0,0,18,10,3,SPlus_data,7,0,0 };
  61. struct Image SMinus_image = { 0,0,18,10,3,SMinus_data,7,0,0 };
  62. struct Image SAutoPlus_image = { 0,0,18,10,2,SAutoPlus_data,3,0,0 };
  63. struct Image SAutoMinus_image = { 0,0,18,10,2,SAutoMinus_data,3,0,0 };
  64.  
  65. #define ZOOM_IN_GDG_ID    1
  66. #define ZOOM_OUT_GDG_ID    2
  67. #define AUTO_PLUS_GDG_ID 3
  68. #define AUTO_MINUS_GDG_ID 4
  69.  
  70. struct Gadget ZoomInGdg = {
  71.     NULL, -17, 0, 18, 10, GFLG_RELRIGHT | GFLG_GADGHCOMP | GFLG_GADGIMAGE,
  72.     GACT_RELVERIFY | GACT_RIGHTBORDER, GTYP_BOOLGADGET, &SPlus_image, NULL, NULL, 0L, NULL, ZOOM_IN_GDG_ID, NULL };
  73.  
  74. struct Gadget ZoomOutGdg = {
  75.     &ZoomInGdg, -17, 0, 18, 10, GFLG_RELRIGHT | GFLG_GADGHCOMP | GFLG_GADGIMAGE,
  76.     GACT_RELVERIFY | GACT_RIGHTBORDER, GTYP_BOOLGADGET, &SMinus_image, NULL, NULL, 0L, NULL, ZOOM_OUT_GDG_ID, NULL };
  77.  
  78. struct Gadget AutoPlusGdg = {
  79.     &ZoomOutGdg, -17, 0, 18, 10, GFLG_RELRIGHT | GFLG_GADGHCOMP | GFLG_GADGIMAGE,
  80.     GACT_RELVERIFY | GACT_RIGHTBORDER, GTYP_BOOLGADGET, &SAutoPlus_image, NULL, NULL, 0L, NULL, AUTO_PLUS_GDG_ID, NULL };
  81.  
  82. struct Gadget AutoMinusGdg = {
  83.     &AutoPlusGdg, -17, 0, 18, 10, GFLG_RELRIGHT | GFLG_GADGHCOMP | GFLG_GADGIMAGE,
  84.     GACT_RELVERIFY | GACT_RIGHTBORDER, GTYP_BOOLGADGET, &SAutoMinus_image, NULL, NULL, 0L, NULL, AUTO_MINUS_GDG_ID, NULL };
  85.  
  86. struct NewWindow nwt = {
  87.     60, 60, 142, 75, 0, 0, IDCMP_CLOSEWINDOW | IDCMP_MOUSEBUTTONS | IDCMP_GADGETUP | IDCMP_NEWSIZE,
  88.     WFLG_ACTIVATE | WFLG_SIZEGADGET | WFLG_SIZEBRIGHT | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_RMBTRAP,
  89.     &AutoMinusGdg, NULL, NULL, NULL, NULL, 120, 61, 0, 0, WBENCHSCREEN };
  90.  
  91. #define PROGRAM_NAME "Zoom! v1.3"
  92. #define AUTHORS_NAME "Stefano Reksten"
  93.  
  94. char *SCR_NAME = PROGRAM_NAME" © 1993 by "AUTHORS_NAME;
  95. char *WND_NAME = PROGRAM_NAME" - S:00 - A:00";
  96.  
  97. struct IntuitionBase *IntuitionBase;
  98. struct GfxBase *GfxBase;
  99. struct Library *BitMapBase, *IconBase;
  100. struct Window *window;
  101.  
  102. struct BitMap *bm, *intermediateBm, *originalBm;
  103. struct MsgPort *TimerMP;
  104. struct timerequest *TimerIO;
  105. ULONG time_delay;
  106. BOOL timer_running = FALSE;
  107.  
  108. UWORD height, width, lastX, lastY;
  109. UBYTE depth, scaling_factor = 2;
  110.  
  111.  
  112. void FreeBitMaps( void )
  113. {
  114. if ( originalBm )
  115.     DisposeBitMap( originalBm );
  116. if ( intermediateBm )
  117.     DisposeBitMap( intermediateBm );
  118. if ( bm )
  119.     DisposeBitMap( bm );
  120. }
  121.  
  122.  
  123. BOOL AllocBitMaps( void )
  124. {
  125. register UWORD w, h;
  126.  
  127. width = ( window->Width - window->BorderLeft - window->BorderRight ) / scaling_factor;
  128. height = ( window->Height - window->BorderTop - window->BorderBottom ) / scaling_factor;
  129.  
  130. w = (width +1) * scaling_factor;
  131. h = (height +1) * scaling_factor;
  132.  
  133. bm = CreateBitMap( w, h, depth );
  134. intermediateBm = CreateBitMap( w, (height+1), depth );
  135. originalBm = CreateBitMap( (width+1), (height+1), depth );
  136.  
  137. if ( bm && intermediateBm && originalBm )
  138.     return( TRUE );
  139. else
  140.     {
  141.     FreeBitMaps();
  142.     return( FALSE );
  143.     }
  144. }
  145.  
  146.  
  147. void Zoom( void )
  148. {
  149. register UWORD X = lastX;
  150. register UWORD Y = lastY;
  151.  
  152. UWORD w = width * scaling_factor / 2;
  153. UWORD h = height * scaling_factor / 2;
  154.  
  155. UWORD sw = window->WScreen->Width;
  156. UWORD sh = window->WScreen->Height;
  157.  
  158. register UWORD xCoord, yCoord, cycle, srvCoord, srvCoord2;
  159.  
  160. if ( X > w/scaling_factor )
  161.     X -= w/scaling_factor;
  162. else    X = 0;
  163.  
  164. if ( X > sw - width )
  165.     X = sw - width;
  166.  
  167. if ( Y > h/scaling_factor )
  168.     Y -= h/scaling_factor;
  169. else    Y = 0;
  170.  
  171. if ( Y > sh - height )
  172.     Y = sh - height;
  173.  
  174. BltBitMap( window->WScreen->RastPort.BitMap, X, Y,
  175.        originalBm, 0, 0,
  176.        width, height, 0xC0, 0xFF, NULL );
  177.  
  178. srvCoord = 0;
  179. for ( xCoord = 0; xCoord < width; xCoord++ )
  180.     {
  181.     for ( cycle = 0; cycle < scaling_factor; cycle++ )
  182.         {
  183.         BltBitMap(
  184.             originalBm, xCoord, 0,
  185.             intermediateBm, srvCoord, 0,
  186.             1, height, 0xC0, 0xFF, NULL );
  187.         srvCoord++;
  188.         }
  189.     }
  190.  
  191. srvCoord = RASSIZE( (width+1)*scaling_factor, (height+1)*scaling_factor );
  192. for ( cycle = 0; cycle < bm->Depth; cycle++ )
  193.     BltClear( bm->Planes[cycle], srvCoord, 1 );
  194.  
  195. srvCoord = 0;
  196. srvCoord2 = width * scaling_factor;
  197. for ( yCoord = 0; yCoord < height; yCoord++ )
  198.     for ( cycle = 0; cycle < scaling_factor; cycle++ )
  199.         {
  200.         BltBitMap(
  201.             intermediateBm, 0, yCoord,
  202.             bm, 0, srvCoord,
  203.             srvCoord2, 1, 0xC0, 0xFF, NULL );
  204.         srvCoord++;
  205.         }
  206.  
  207. WaitTOF();
  208. BltBitMapRastPort( bm, 0, 0, window->RPort, window->BorderLeft, window->BorderTop, window->Width - window->BorderLeft - window->BorderRight, window->Height - window->BorderTop - window->BorderBottom, 0xC0 );
  209. }
  210.  
  211.  
  212. BOOL SetUpTimer( void )
  213. {
  214. if ( TimerMP = CreateMsgPort() )
  215.     {
  216.     if ( TimerIO = (struct timerequest *)CreateExtIO(TimerMP, sizeof( struct timerequest ) ) )
  217.         {
  218.         if ( !(OpenDevice( "timer.device", UNIT_VBLANK, (struct IORequest *)TimerIO, 0 ) ) )
  219.             {
  220.             TimerIO->tr_node.io_Command = TR_ADDREQUEST;
  221.             TimerIO->tr_time.tv_secs = time_delay;
  222.             SendIO( (struct IORequest *)TimerIO );
  223.             return( TRUE );
  224.             }
  225.         DeleteExtIO( (struct IORequest *)TimerIO );
  226.         }
  227.     DeleteMsgPort( TimerMP );
  228.     }
  229. return( FALSE );
  230. }
  231.  
  232.  
  233. void RemoveTimer( void )
  234. {
  235. if ( TimerIO )
  236.     {
  237.     if ( !( CheckIO( (struct IORequest *)TimerIO ) ) )
  238.         AbortIO( (struct IORequest *)TimerIO );
  239.     WaitIO( (struct IORequest *)TimerIO );
  240.     CloseDevice( (struct IORequest *)TimerIO );
  241.     DeleteExtIO( (struct IORequest *)TimerIO );
  242.     DeletePort( TimerMP );
  243.     TimerIO = NULL;
  244.     }
  245. }
  246.  
  247.  
  248. void SetTitles( void )
  249. {
  250. WND_NAME[15] = '0' + scaling_factor / 10;
  251. WND_NAME[16] = '0' + scaling_factor % 10;
  252.  
  253. if ( !time_delay )
  254.     {
  255.     WND_NAME[22] = 'N';
  256.     WND_NAME[23] = 'A';
  257.     }
  258. else
  259.     {
  260.     if ( time_delay < 100 )
  261.         {
  262.         WND_NAME[22] = '0' + time_delay / 10;
  263.         WND_NAME[23] = '0' + time_delay % 10;
  264.         }
  265.     else
  266.         {
  267.         WND_NAME[22] = '?';
  268.         WND_NAME[23] = '!';
  269.         }
  270.     }
  271.  
  272. SetWindowTitles( window, WND_NAME, SCR_NAME );
  273. }
  274.  
  275. void ProcessMessages( void )
  276. {
  277. register BOOL stay = TRUE;
  278. register ULONG signal, mask = 1L<<window->UserPort->mp_SigBit | SIGBREAKF_CTRL_C;
  279. register struct IntuiMessage *msg;
  280. register struct Message *timerMsg;
  281. register struct Gadget *gdg;
  282. register ULONG class;
  283. register UWORD code;
  284.  
  285. while( stay )
  286.     {
  287.     if ( timer_running )
  288.         mask |= 1L<<TimerMP->mp_SigBit;
  289.  
  290.     signal = Wait ( mask );
  291.  
  292.     if ( signal & SIGBREAKF_CTRL_C )
  293.         stay = FALSE;
  294.  
  295.     if ( timer_running && signal & 1L<<TimerMP->mp_SigBit )
  296.         {
  297.         if ( timerMsg = GetMsg( TimerMP ) )
  298.             {
  299.             Zoom();
  300.             TimerIO->tr_node.io_Command = TR_ADDREQUEST;
  301.             TimerIO->tr_time.tv_secs = time_delay;
  302.             SendIO( (struct IORequest *)TimerIO );
  303.             }
  304.         }
  305.  
  306.     if ( signal & 1L<<window->UserPort->mp_SigBit )
  307.         {
  308.         while ( msg = (struct IntuiMessage *)GetMsg( window->UserPort ) )
  309.             {
  310.             class = msg->Class;
  311.             code = msg->Code;
  312.  
  313.             switch( class )
  314.                 {
  315.                 case IDCMP_CLOSEWINDOW:
  316.                     stay = FALSE;
  317.                     break;
  318.                 case IDCMP_NEWSIZE:
  319.                     FreeBitMaps();
  320.                     width = ( window->Width - window->BorderLeft - window->BorderRight -1 ) / scaling_factor;
  321.                     height = ( window->Height - window->BorderTop - window->BorderBottom -1 ) / scaling_factor;
  322.                     if ( stay = AllocBitMaps() )
  323.                         Zoom();
  324.                     break;
  325.                 case IDCMP_MOUSEBUTTONS:
  326.                     switch( code )
  327.                         {
  328.                         case MENUUP:
  329.                             lastX = IntuitionBase->MouseX;
  330.                             lastY = IntuitionBase->MouseY;
  331.                             if ( !( window->WScreen->ViewPort.Modes & LACE ) )
  332.                                 lastY >>= 1;
  333.                             if ( (window->WScreen->ViewPort.Modes & SUPERHIRES ) )
  334.                                 lastX <<= 1;
  335.                             else
  336.                             if ( !(window->WScreen->ViewPort.Modes & HIRES ) )
  337.                                 lastX >>= 1;
  338.                              Zoom();
  339.                             break;
  340.                         default:
  341.                             break;
  342.                         }
  343.                     break;
  344.                 case IDCMP_GADGETUP:
  345.                     gdg = (struct Gadget *)msg->IAddress;
  346.                     if ( gdg->GadgetID == ZOOM_IN_GDG_ID && scaling_factor < 40 )
  347.                         {
  348.                         FreeBitMaps();
  349.                         scaling_factor++;
  350.                         width = ( window->Width - window->BorderLeft - window->BorderRight -1 ) / scaling_factor;
  351.                         height = ( window->Height - window->BorderTop - window->BorderBottom -1 ) / scaling_factor;
  352.                         if ( stay = AllocBitMaps() )
  353.                             Zoom();
  354.                         }
  355.                     else
  356.                     if ( gdg->GadgetID == ZOOM_OUT_GDG_ID && scaling_factor > 2 )
  357.                         {
  358.                         FreeBitMaps();
  359.                         scaling_factor--;
  360.                         width = ( window->Width - window->BorderLeft - window->BorderRight -1 ) / scaling_factor;
  361.                         height = ( window->Height - window->BorderTop - window->BorderBottom -1 ) / scaling_factor;
  362.                         if ( stay = AllocBitMaps() )
  363.                             Zoom();
  364.                         }
  365.                     else
  366.                     if ( gdg->GadgetID == AUTO_PLUS_GDG_ID )
  367.                         {
  368.                         time_delay++;
  369.                         if ( timer_running == FALSE )
  370.                             {
  371.                             if ( timer_running = SetUpTimer() )
  372.                                 OnGadget( &AutoMinusGdg, window, NULL );
  373.                             }
  374.                         }
  375.                     else
  376.                     if ( gdg->GadgetID == AUTO_MINUS_GDG_ID )
  377.                         {
  378.                         if ( time_delay && timer_running )
  379.                             {
  380.                             time_delay--;
  381.                             RemoveTimer();
  382.                             if ( !time_delay )
  383.                                 {
  384.                                 timer_running = FALSE;
  385.                                 OffGadget( &AutoMinusGdg, window, NULL );
  386.                                 }
  387.                             else    SetUpTimer();
  388.                             }
  389.                         }
  390.                     SetTitles();
  391.                     break;
  392.                 default:
  393.                     break;
  394.                 }
  395.             ReplyMsg( (struct Message *)msg );
  396.             }
  397.         }
  398.     }
  399. }
  400.  
  401.  
  402. void main( int argc, char *argv[] )
  403. {
  404. if ( argc )
  405.     {
  406.     LONG args[6];
  407.     struct RDArgs *rdargs;
  408.  
  409.     memset( args, 0, 24 );
  410.     if ( rdargs = ReadArgs( "Auto/N,Scale/N,Left/N,Top/N,Width/N,Height/N", args, NULL ) )
  411.         {
  412.         if ( args[0] ) { time_delay = *((ULONG *)args[0]); timer_running = TRUE; }
  413.         if ( args[1] ) scaling_factor = *((ULONG *)args[1]);
  414.         if ( args[2] ) nwt.LeftEdge = *((ULONG *)args[2]);
  415.         if ( args[3] ) nwt.TopEdge = *((ULONG *)args[3]);
  416.         if ( args[4] ) nwt.Width = *((ULONG *)args[4]);
  417.         if ( args[5] ) nwt.Height = *((ULONG *)args[5]);
  418.         FreeArgs( rdargs );
  419.         }
  420.     }
  421. else
  422. if ( IconBase = OpenLibrary( "icon.library", 0L ) )
  423.     {
  424.     char **ttypes = ArgArrayInit( argc, argv );
  425.  
  426.     if ( time_delay = ArgInt( ttypes, "AUTO", 0 ) )
  427.         timer_running = TRUE;
  428.     scaling_factor = ArgInt( ttypes, "SCALE", 2 );
  429.     if ( scaling_factor < 2 || scaling_factor > 40 )
  430.         scaling_factor = 2;
  431.     nwt.LeftEdge = ArgInt( ttypes, "LEFT", 60 );
  432.     nwt.TopEdge = ArgInt( ttypes, "TOP", 60 );
  433.     nwt.Width = ArgInt( ttypes, "WIDTH", 142 );
  434.     nwt.Height = ArgInt( ttypes, "HEIGHT", 75 );
  435.  
  436.     ArgArrayDone();
  437.     CloseLibrary( IconBase );
  438.     }
  439.  
  440. if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 0L ) )
  441.     {
  442.     if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 0L ) )
  443.         {
  444.         if ( BitMapBase = OpenLibrary( "bitmap.library", 0L ) )
  445.             {
  446.             depth = IntuitionBase->ActiveScreen->BitMap.Depth;
  447.  
  448.             ZoomInGdg.TopEdge = IntuitionBase->ActiveScreen->Font->ta_YSize + 3;
  449.             ZoomOutGdg.TopEdge = ZoomInGdg.TopEdge + 10;
  450.             AutoPlusGdg.TopEdge = ZoomOutGdg.TopEdge + 10;
  451.             AutoMinusGdg.TopEdge = AutoPlusGdg.TopEdge + 10;
  452.  
  453.             nwt.MaxWidth = IntuitionBase->ActiveScreen->Width;
  454.             nwt.MaxHeight = IntuitionBase->ActiveScreen->Height;
  455.  
  456.             if ( window = OpenWindow( &nwt ) )
  457.                 {
  458.                 SetTitles();
  459.                 SetAPen( window->RPort, 0 );
  460.                 SetPointer( window, Lens_data, 16L, 16L, -6, -6 );
  461.                 if ( AllocBitMaps() )
  462.                     {
  463.                     if ( timer_running )
  464.                         timer_running = SetUpTimer();
  465.                     if ( !timer_running || !time_delay )
  466.                         OffGadget( &AutoMinusGdg, window, NULL );
  467.                     lastX = 0;
  468.                     lastY = 0;
  469.                     Zoom();
  470.                     ProcessMessages();
  471.                     FreeBitMaps();
  472.                     if ( timer_running )
  473.                         RemoveTimer();
  474.                     }
  475.                 ClearPointer( window );
  476.                 CloseWindow( window );
  477.                 }
  478.             CloseLibrary( BitMapBase );
  479.             }
  480.         CloseLibrary( (struct Library *)GfxBase );
  481.         }
  482.     CloseLibrary( (struct Library *)IntuitionBase );
  483.     }
  484. }
  485.